package com.yang.mybatis.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisConfiguration implements Serializable {
    private Map<String, MybatisEnvironment> id2EnvironmentMap = new HashMap<>();

    private MybatisEnvironment defaultMybatisEnvironment;

    private List<String> mapperPaths = new ArrayList<>();

    private Map<String, MybatisSqlStatement> mapperMethod2SqlStatementsMap = new HashMap<>();

    private Map<String, MybatisMapperXmlConfiguration> mapperXmlConfigurationMap = new HashMap<>();

    public void putMapperMethod2MybatisSqlStatement(String mapperMethod, MybatisSqlStatement mybatisSqlStatement) {
        this.mapperMethod2SqlStatementsMap.put(mapperMethod, mybatisSqlStatement);
    }

    public MybatisSqlStatement getMybatisSqlStatement(String mapperMethod) {
        return this.mapperMethod2SqlStatementsMap.get(mapperMethod);
    }

    public Map<String, MybatisSqlStatement> getMapperMethod2SqlStatementsMap() {
        return this.mapperMethod2SqlStatementsMap;
    }


    public void addEnvironment(String id, MybatisEnvironment mybatisEnvironment) {
        this.id2EnvironmentMap.put(id, mybatisEnvironment);
    }

    public MybatisEnvironment getEnvironment(String id) {
        return id2EnvironmentMap.get(id);
    }

    public MybatisEnvironment getDefaultMybatisEnvironment() {
        return defaultMybatisEnvironment;
    }

    public void setDefaultMybatisEnvironment(MybatisEnvironment defaultMybatisEnvironment) {
        this.defaultMybatisEnvironment = defaultMybatisEnvironment;
    }

    public void addMapperPath(String mapperPath) {
        this.mapperPaths.add(mapperPath);
    }

    public List<String> getMapperPaths() {
        return this.mapperPaths;
    }

    public List<MybatisEnvironment> getEnvironments() {
        return new ArrayList<>(id2EnvironmentMap.values());
    }

    public void putMapperXmlConfiguration(String mapperName, MybatisMapperXmlConfiguration mybatisMapperXmlConfiguration) {
        this.mapperXmlConfigurationMap.put(mapperName, mybatisMapperXmlConfiguration);
    }

    public MybatisMapperXmlConfiguration getMybatisMapperXmlConfiguration(String mapperName) {
        return this.mapperXmlConfigurationMap.get(mapperName);
    }

    public Map<String, MybatisMapperXmlConfiguration> getMapperXmlConfigurationMap() {
        return this.mapperXmlConfigurationMap;
    }
}
